/*
 * @Description  :
 * @Version      : 1.0
 * @Author       : Shiming
 * @Date         : 2021-12-21 10:14:52
 * @LastEditors  : Shiming
 * @LastEditTime : 2022-01-18 17:21:43
 * @FilePath     : \\tms-obc-web\\src\\app\\routes\\order-management\\modal\\vehicle\\cancel\\cancel.component.ts
 * Copyright (C) 2022 huzhenhong. All rights reserved.
 */
import { Component, OnInit, ViewChild } from '@angular/core';
import {
  SFComponent, SFSchema,
  SFTextareaWidgetSchema,
  SFUISchema
} from '@delon/form';
import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal';
import { OrderManagementService } from '../../../services/order-management.service';

@Component({
  selector: 'app-order-management-cancel',
  templateUrl: './cancel.component.html'
})
export class OneCarOrderCancelComponent implements OnInit {
  record: any = {};
  i: any;
  @ViewChild('sf', { static: false }) sf!: SFComponent;
  schema: SFSchema = {};
  ui: SFUISchema = {};
  constructor(private modalRef: NzModalRef, private modal: NzModalService, public service: OrderManagementService) {}

  ngOnInit(): void {
    this.initSF();
    console.log(this.i.billStatusLabel);
  }
  initSF() {
    this.schema = {
      properties: {
        cancelReason: {
          type: 'string',
          title: '取消原因',
          ui: {
            widget: 'textarea',
            autosize: { minRows: 3, maxRows: 6 }
          } as SFTextareaWidgetSchema
        }
      },
      required: ['reason']
    };
    this.ui = {
      '*': {
        spanLabelFixed: 100,
        grid: { span: 20 }
      }
    };
  }
  save(value: any): void {
    if (this.i?.billStatus === '1') {
      // 待接单状态
      this.modal.confirm({
        nzTitle: '<i>是否确定立即取消运单！</i>',
        nzOnOk: () =>
          this.service.request(this.service.$api_get_cancelAnOrder, { id: this.i?.id, ...this.sf?.value }).subscribe(res => {
            if (res) {
              this.modalRef.close(true);
            }
          }),
        nzOnCancel: () => this.modalRef.destroy()
      });
    } else {
      this.service.request(this.service.$api_get_cancelAnOrder, { id: this.i?.id, ...this.sf?.value }).subscribe(res => {
        if (res) {
          this.modalRef.close(true);
        }
      });
    }

    this.modalRef.close(true);
  }

  close(): void {
    this.modalRef.destroy();
  }
}
